<?php 
    session_start();
    if(!isset($_SESSION['islogined'])||@$_SESSION['idposition']==3)
        header("location:./Login.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="app.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
    <?php include 'header1.php'; ?>
    <div class="container">
        <ol class="breadcrumb path-nav">
            <li><a href="./Home.php">Home</a></li>
            <li><a href="./Module.php">Module Management</a></li>
            <li class="active">Add New Module</li>
        </ol>
    </div>
    <div class="container addstaff-form">
        <h2 class='form-header'>New Module Information</h2>
        <form role="form" action="" method="POST">
            <div class="col-md-4 col-md-offset-1">
                <label>Module Code</label>
                <div class="input-group input-formgroup" >
                    <input id='code' type="text" class="form-control " required="required">
                </div>
                <label>Module Title</label>
                <div class="input-group input-formgroup" >
                    <input id='title' type="text" class="form-control " required="required">
                </div>
                <label>Semester</label>
                <select id='Semster' class="form-control input-formgroup">
                    <option>First Semester</option>
                    <option>Second Semester</option>
                    <option>Whole Session</option>
                </select>
                <label>Credit Value</label>
                <div class="input-group input-formgroup" >
                    <input id='credit' type="number" class="form-control " required="required">
                </div>
                   
            </div>
            <div name="infor_staff" class="col-md-4 col-md-offset-2">
                <label>Number of Lectures</label>
                <div class="input-group input-formgroup" >
                    <input id='lecture' type="number" class="form-control " required="required">
                </div> 
                <label>Number of Tutorials</label>
                <div class="input-group input-formgroup" >
                    <input id='tutorial' type="number" class="form-control " required="required">
                </div>
                <label>Number of Labs</label>
                <div class="input-group input-formgroup" >
                    <input id='lab' type="number" class="form-control " required="required">
                </div>
                <label>Number of Students</label>
                <div class="input-group input-formgroup" >
                    <input id='studentnum' type="number" class="form-control " required="required">
                </div>
            </div>
            </form>
            <div class="col-md-4 col-md-offset-4 ">         
                <button id='insert_module' class="btn btn-default btn-lg form-button">Submit</button>
                <button class="btn btn-default btn-lg form-button">Reset</button>
            </div>           
    </div>
<script src="jquery-3.0.0.min.js"></script>
<script src="bootstrap.min.js"></script>
<script>
    $(function(){
        $('#insert_module').click(function(){
            $('.success-modify').remove();
            $('.fail-modify').remove();
            var code=$('#code').val();
            var title=$('#title').val();
            var Semster=$('#Semster').val();
            var lecture=$('#lecture').val();
            var tutorial=$('#tutorial').val();
            var lab=$('#lab').val();
            var credit=$('#credit').val();
            var studentnum=$('#studentnum').val();
            if(code==''||title==''){
                $('.form-header').before("<div class='fail-modify'>The ModuleCode and ModuleTitle must be filled</div>");
            }
            else{
                $.post("infor_module.php",{
                type:'insert_module',
                code:code,
                title:title,
                Semster:Semster,
                lecture:lecture,
                tutorial:tutorial,
                lab:lab,
                credit:credit,
                studentnum:studentnum
                },function(data){
                    $('.form-header').before(data);
                });
            }
        });
    });
</script>
</body>
</html>